package com.b2bpsssm.service.impl;

import com.b2bpsssm.common.R;
import com.b2bpsssm.mapper.PaymentOrderMapper;
import com.b2bpsssm.pojo.PurchasePassOrder;
import com.b2bpsssm.service.PaymentOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PaymentOrderServiceImpl implements PaymentOrderService {
    @Autowired
    private PaymentOrderMapper paymentOrderMapper;
  // 查询    有分页
    @Override
    public R queryPaymentOrderList(Integer currentPage, Integer pageSize) {
        R r = new R();
        Integer start = (currentPage - 1) * pageSize;//分页第一个参数
        Integer off = pageSize; //分页第二个参数
        //查询后的数据
        List<PurchasePassOrder> List = paymentOrderMapper.queryPaymentOrderList(start, off);
        //成功后返回的结果
        r.setCode(200);
        r.setMassage("success");
        r.setData(List);
        return r;
    }
      // 根据单据编号  查询
    @Override
    public R queryPaymentOrderByNumber(String document_no) {
        R r = new R();
        List<PurchasePassOrder> number = paymentOrderMapper.queryPaymentOrderByNumber(document_no);
        r.setMassage("success");
        r.setData(number);
        r.toString();
        r.setCode(200);
        return r;

    }
  // 根据供货方查询
    @Override
    public R queryPaymentOrderBySupplier(Integer currentPage, Integer pageSize, String payment_order_supplier) {
        R r = new R();
        Integer start = (currentPage - 1) * pageSize;//分页第一个参数
        Integer off = pageSize; //分页第二个参数
        List<PurchasePassOrder> payment_orders = paymentOrderMapper.queryPaymentOrderBySupplier(start, off, payment_order_supplier);
        r.setMassage("success");
        r.setData(payment_orders);
        r.setCode(200);
        r.toString();
        return r;
    }
     //已供货方  时间关键字搜索
    @Override
    public R selPaymentOrderLikeSupplier(Integer currentPage, Integer pageSize, String sub_date1, String sub_date2, String supplier) {
        R r = new R();
        Integer start = (currentPage - 1) * pageSize;//分页第一个参数
        Integer off = pageSize; //分页第二个参数
        List<PurchasePassOrder> list = paymentOrderMapper.selPaymentOrderLikeSupplier(start, off, sub_date1, sub_date2, supplier);
        //成功后返回的结果
        r.setCode(200);
        r.setMassage("success");
        r.setData(list);

        return r;

    }
      //添加付款单
    @Override
    public R addPaymentOrder(PurchasePassOrder purchasePassOrder) {
        R r = new R();
        try {
            int result = paymentOrderMapper.addPaymentOrder(purchasePassOrder);
            if (result > 0) {
                r.setCode(200);
                r.setMassage("添加成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMassage("系统开小差了，请联系管理员！");
        }
        return r;


    }
}
